# -*- coding:utf-8 -*-
"""
@Author    :Ven
@FileName  :InternetSettingsActivity.py
@Time      :2021/12/29 14:58
@文档说明   :网络设置
"""
from appium.webdriver.common.touch_action import TouchAction

from activity.IdentificationActivity import IdentificationActivity
from activity.LoginActivity import LoginActivity
from activity.MainMenuActivity import MainMenuActivity
from common.baseactivity import  BaseActivity


class InternetSettingsActivity(BaseActivity):
    def __init__(self):
        super().__init__()
        # 网络设置
        self.radio_dhcp = ('id','com.sykean.biometrics:id/radio_dhcp')
        self.radio_static = ('id','com.sykean.biometrics:id/radio_static')
        device_ip_resourceId = 'resourceId("com.sykean.biometrics:id/edit_device_ip").childSelector(resourceId("com.sykean.biometrics:id/txt_edit_value"))'
        self.device_ip = ('-android uiautomator',device_ip_resourceId)
        device_mask_resourceId = 'resourceId("com.sykean.biometrics:id/edit_device_mask").childSelector(resourceId("com.sykean.biometrics:id/txt_edit_value"))'
        self.device_mask =('-android uiautomator',device_mask_resourceId)
        device_gate_resourceId = 'resourceId("com.sykean.biometrics:id/edit_device_gate").childSelector(resourceId("com.sykean.biometrics:id/txt_edit_value"))'
        self.device_mask = ('-android uiautomator', device_gate_resourceId)
        device_dns1_resourceId = 'resourceId("com.sykean.biometrics:id/edit_device_dns1").childSelector(resourceId("com.sykean.biometrics:id/txt_edit_value"))'
        self.device_mask = ('-android uiautomator', device_dns1_resourceId)
        device_dns2_resourceId = 'resourceId("com.sykean.biometrics:id/edit_device_dns2").childSelector(resourceId("com.sykean.biometrics:id/txt_edit_value"))'
        self.device_mask = ('-android uiautomator', device_dns2_resourceId)

        # 网络设置dialog
        self.dialog_device_ip = ('id','com.sykean.biometrics:id/edit_dialog_device_ip')
        self.dialog_device_mask = ('id','com.sykean.biometrics:id/edit_dialog_device_mask')
        self.dialog_device_gate = ('id','com.sykean.biometrics:id/edit_dialog_device_gate')
        self.dialog_device_dns1 = ('id', 'com.sykean.biometrics:id/edit_dialog_device_dns1')
        self.dialog_device_dns2= ('id', 'com.sykean.biometrics:id/edit_dialog_device_dns2')
        self.btn_dialog_cancel = ('id','com.sykean.biometrics:id/btn_dialog_cancel')
        self.btn_dialog_ok = ('id', 'com.sykean.biometrics:id/btn_dialog_ok')



        # 服务器设置
        server_ip_locator = 'resourceId("com.sykean.biometrics:id/edit_server_ip").childSelector(resourceId("com.sykean.biometrics:id/txt_edit_value"))'
        self.server_ip = ('-android uiautomator', server_ip_locator)

        server_port_locator = 'resourceId("com.sykean.biometrics:id/edit_server_port").childSelector(resourceId("com.sykean.biometrics:id/txt_edit_value"))'
        self.server_port = ('-android uiautomator', server_port_locator)
        time_server_port_locator = 'resourceId("com.sykean.biometrics:id/edit_time_server_port").childSelector(resourceId("com.sykean.biometrics:id/txt_edit_value"))'
        self.time_server_port = ('-android uiautomator', time_server_port_locator)
        # dialog
        self.dialog_content = ('id', 'com.sykean.biometrics:id/edit_dialog_content')
        self.btn_dialog_cancel = ('id', 'com.sykean.biometrics:id/btn_dialog_cancel')
        self.btn_dialog_ok = ('id', 'com.sykean.biometrics:id/btn_dialog_ok')

        #剪切、赋值
        self.copy = ('-android uiautomator','text("复制")')
        self.clipboard = ('-android uiautomator','text("剪切")')

    def setInternet(self):
        self.ele_click(self.radio_static)
        self.ele_sendkeys(self.dialog_device_ip,'192.168.137.138')
        self.ele_sendkeys(self.dialog_device_mask,'192.168.253.253')
        self.ele_click(self.btn_dialog_cancel)

    def getInternetInfo(self):
        self.ele_click(self.radio_static)
        # 双击设备IP
        TouchAction(self.driver).tap(self.ele_locator(self.dialog_device_ip),count=2).release().perform()
        # 点击提示“复制”
        TouchAction(self.driver).tap(x=504,y=49).release().perform()
        # 清空子网掩码
        self.ele_clear(self.dialog_device_mask)
        self.ele_click(self.dialog_device_mask)
        # 执行ctrl+v https://developer.android.google.cn/reference/android/view/KeyEvent.html#KEYCODE_COPY
        self.ele_keycode(279)
        print(self.driver.get_clipboard_text())



if __name__ == '__main__':
    IdentificationActivity().loginLogo()
    LoginActivity().login()
    MainMenuActivity().to_menu_internet()
    #InternetSettingsActivity().setInternet()
    InternetSettingsActivity().getInternetInfo()